package org.example.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String S59_QUEUE_1 = "s59_queue_1";

    public static final String S59_QUEUE_2 = "s59_queue_2";

    public static final String S59_DIRECT_EXCHANGE = "s59_direct_exchange";

    public static final String S59_TOPIC_EXCHANGE = "s59_topic_exchange";

    public static final String S59_FANOUT_EXCHANGE = "s59_fanout_exchange";

    @Bean
    public Queue queue1(){
        return new Queue(S59_QUEUE_1,true);
    }

    @Bean
    public Queue queue2(){
        return new Queue(S59_QUEUE_2,true);
    }


    /**
     * 广播（泛型） 查询跟路由key无关 全部会发送
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(S59_FANOUT_EXCHANGE);
    }

    @Bean
    public Binding binding1(){
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }


    /*
     *  模糊查询
     */
//    @Bean
//    public TopicExchange topicExchange(){
//        return new TopicExchange(S59_TOPIC_EXCHANGE);
//    }
//
//    @Bean
//    public Binding binding1(){
//        return BindingBuilder.bind(queue1()).to(topicExchange()).with("#.red.#");
//    }
//
//    @Bean
//    public Binding binding2(){
//        return BindingBuilder.bind(queue2()).to(topicExchange()).with("#.green.#");
//    }


    /*
     *  精准查询
     */
//    @Bean
//    public DirectExchange directExchange(){
//        return new DirectExchange(S59_DIRECT_EXCHANGE);
//    }
//
//    @Bean
//    public Binding binding1(){
//        return BindingBuilder.bind(queue1()).to(directExchange()).with("red");
//    }
//
//    @Bean
//    public Binding binding2(){
//        return BindingBuilder.bind(queue2()).to(directExchange()).with("green");
//    }


}
